/*
 * 	Flan.Zeng 2000-2006	http://git.oschina.net/signup?inviter=flan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.flan.stock.bean;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.graphics.Typeface;

/**
 * 绘制分时走势的坐标系
 * @author flan
 * @date   2005年00月4日
 */
public class FsCoordinateSystem {
	
	private int viewWidth,viewHeight;	//分时走势视图的长，宽
	private int heightFsBorder,heightFslBorder;	//分时线，分时量的边框高度
	private Paint paint;
	private Canvas canvas;
	private Path path;
	
	public FsCoordinateSystem(int viewWidth, int viewHeight) {
		super();
		path = new Path();
		this.viewWidth = viewWidth-1;
		this.viewHeight = viewHeight-1;
	}
	
	public void drawCoordinateSystem(Canvas canvas,Paint paint){
		
		this.paint = paint;
		this.canvas = canvas;
		
		paint.setColor(Color.WHITE);
		canvas.drawRGB(255, 255, 255);	//绘制背景颜色
		
		paint.setStyle(Style.STROKE);
		paint.setColor(Color.LTGRAY);
		paint.setStrokeWidth(1);
		paint.setPathEffect(null);	//设置虚线效果为null
		//绘制分时走势外边框
		heightFsBorder = viewHeight/19*12;
		canvas.drawRect(1, 1, viewWidth, heightFsBorder, paint);
		//绘制分时量外边框
		heightFslBorder = viewHeight/19*13;
		canvas.drawRect(1, heightFslBorder, viewWidth, viewHeight, paint);
		
		drawXuXian();
		drawXData();
	}
	
	//画参考系中的虚线
	private void drawXuXian(){
		
		paint.setStyle(Style.STROKE);
		paint.setColor(Color.LTGRAY);
		paint.setStrokeWidth(1);
		//绘制参考虚线
		PathEffect effect = new DashPathEffect(new float[] { 2, 4,}, 1);
		paint.setPathEffect(effect);
		
		//绘制虚线参考线 横线
		int margin = 5;
		int heightFsXuXian = heightFsBorder - margin*2;
		path.moveTo(1,heightFsXuXian/4*0+margin);
		path.lineTo(viewWidth, heightFsXuXian/4*0+margin);
		canvas.drawPath(path, paint);	//第一条
		path.moveTo(1,heightFsXuXian/4*1+margin);
		path.lineTo(viewWidth, heightFsXuXian/4*1+margin);
		canvas.drawPath(path, paint);	//第二条
		path.moveTo(1,heightFsXuXian/4*2+margin);
		path.lineTo(viewWidth, heightFsXuXian/4*2+margin);
		canvas.drawPath(path, paint);	//第三条
		path.moveTo(1,heightFsXuXian/4*3+margin);
		path.lineTo(viewWidth, heightFsXuXian/4*3+margin);
		canvas.drawPath(path, paint);	//第四条
		path.moveTo(1,heightFsXuXian/4*4+margin);
		path.lineTo(viewWidth, heightFsXuXian/4*4+margin);
		canvas.drawPath(path, paint);	//第五条
		
		path.moveTo(1,viewHeight/19*16+5);
		path.lineTo(viewWidth, viewHeight/19*16+margin);
		canvas.drawPath(path, paint);	//第六条
		
		//绘制虚线参考线 竖线
		int widthXuXian = viewWidth;
		path.moveTo(widthXuXian/4*1,margin);
		path.lineTo(widthXuXian/4*1, heightFsBorder-margin);
		canvas.drawPath(path, paint);	//第一条
		path.moveTo(widthXuXian/4*2,margin);
		path.lineTo(widthXuXian/4*2, heightFsBorder-margin);
		canvas.drawPath(path, paint);	//第二条
		path.moveTo(widthXuXian/4*3,margin);
		path.lineTo(widthXuXian/4*3, heightFsBorder-margin);
		canvas.drawPath(path, paint);	//第三条
		
		path.moveTo(widthXuXian/4*1,heightFslBorder);
		path.lineTo(widthXuXian/4*1, viewHeight);
		canvas.drawPath(path, paint);	//第四条
		path.moveTo(widthXuXian/4*2,heightFslBorder);
		path.lineTo(widthXuXian/4*2, viewHeight);
		canvas.drawPath(path, paint);	//第五条
		path.moveTo(widthXuXian/4*3,heightFslBorder);
		path.lineTo(widthXuXian/4*3, viewHeight);
		canvas.drawPath(path, paint);	//第六条
		
	}
	
	//绘制X轴数据
	private void drawXData(){
		
		paint.setColor(Color.DKGRAY);
		paint.setStyle(Style.FILL);
		paint.setPathEffect(null);
		paint.setStrokeWidth(3f);
		paint.setTextSize(14);
		paint.setTypeface(Typeface.DEFAULT_BOLD);
		paint.setTextAlign(Align.LEFT);
		canvas.drawText("09:30", 1, heightFsBorder+15, paint);
		paint.setTextAlign(Align.CENTER);
		canvas.drawText("11:30", viewWidth/2, heightFsBorder+15, paint);
		paint.setTextAlign(Align.RIGHT);
		canvas.drawText("15:00", viewWidth, heightFsBorder+15, paint);
		
	}
	
	private void drawYData(){
		
	}
	
	public int getViewWidth() {
		return viewWidth;
	}
	public void setViewWidth(int viewWidth) {
		this.viewWidth = viewWidth;
	}

	public int getViewHeight() {
		return viewHeight;
	}
	public void setViewHeight(int viewHeight) {
		this.viewHeight = viewHeight;
	}
	
}
